package com.ming.attendance.controller;

import com.ming.attendance.po.EventUser;
import com.ming.attendance.model.EventUserListModel;
import com.ming.attendance.po.EventUserOpengid;
import com.ming.attendance.po.ResponseBean;
import com.ming.attendance.service.EventUserService;
import com.ming.attendance.utils.JWTUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/EventUser")
public class EventUserController {
    @Autowired
    private EventUserService us;

    @PostMapping("/createEventUser")
    ResponseBean<Integer> createEventUser(@RequestHeader("Authorization") String token,EventUserOpengid eventUser){
        String openid = JWTUtils.getOpenid(token);
        eventUser.setOpenid(openid);
        System.out.println("eventUser: >>>>> "+eventUser);
        return us.createEventUser(eventUser);
    }

    @PostMapping("/signUp")
    ResponseBean<Integer> signUp(@RequestHeader("Authorization") String token,String eventid){
        String openid = JWTUtils.getOpenid(token);
        System.out.println(eventid);
        System.out.println(openid);
        return us.signUp(eventid,openid);
    }

    @GetMapping("/getEventUser")
    ResponseBean<EventUser> getEventUser(@RequestHeader("Authorization") String token,String eventid){
        String openid = JWTUtils.getOpenid(token);
        return us.getEventUser(eventid, openid);
    }

    @GetMapping("/getEventUsersByEventid")
    ResponseBean<EventUserListModel> getEventUsersByEventid(String eventid){
        return us.getEventUsersByEventid(eventid);
    }
}
